/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller;

//import java.nio.channels.SeekableByteChannel;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.event.ValueChangeEvent;
import queenb.net.entitybean.N500;
import queenb.web.crm.store.CustomerStore;
import queenb.web.store.N500Store;
import queenb.web.util.ContextUtil;
import java.util.*;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import queenb.net.entitybean.Q000;
import queenb.web.store.Q000Store;



import queenb.web.util.ComboboxUtil;
import queenb.web.util.SessionProvider;
import queenb.web.util.Util;

/**
 *
 * @author Nguyen Hung
 */
public class N500Controller extends QueenbController {

    private int FN000;
    private int FN850;
    private int FN450;
    private int PN100;
    private Date ndn501;
    private Date ndn505;
    private String nv502;
    private ComboboxUtil comboboxUtil;
    private N500Store n500Store;
    private List<SelectItem> combN000;
    private List<SelectItem> combN850 = new ArrayList<SelectItem>();
    private List<SelectItem> combN450;
    private List<SelectItem> combN100;
    private int adddate1;
    private int phongban;
    private int bophan;
    private int flagcalender;
    private int beginContructor;
    private List<SelectItem> comN900 = new ArrayList<SelectItem>();
    private String status;
    private int PN500;
    private String nameMail;
    private String passMail;
    private String nameMailTo;
    private String hotennghi;
    private String massage;
    private String note;
    private long dateStart;
    private long dateEnd;
    private Date dateF;
    private Date dateT;
    private int h1;
    private int h2;
    private int h3;
    private int h4;
    private String pageString;// ohan biet ngay thang
    private int pn500;
    public N500Controller() {
        getKapiMenu().setAdmin(false);
        getKapiMenu().setMainmenu1("m11");

        n500Store = new N500Store();
        comboboxUtil = new ComboboxUtil();
        Object StObject = getRequest().getParameter("end");
        
        if (StObject != null) {
            if (StObject != null) {
                dateEnd = Long.parseLong(StObject.toString());
                SessionProvider.setSessionMapValue("DATEHOLIDAYEND", dateEnd);
            }
        }
        
        Object StObject0 = getRequest().getParameter("type");
        if (StObject0 != null) {
            phongban = Util.parseInt(StObject0);
            if(phongban == 0){
                if(SessionProvider.getSessionMapValue("SEARCHDATECALENDER")!=null){
                    SessionProvider.removeSessionMapValue("SEARCHDATECALENDER");
                }
                 if(SessionProvider.getSessionMapValue("SEARCHDATECALENDER1")!=null){
                    SessionProvider.removeSessionMapValue("SEARCHDATECALENDER1");
                }
                
               
            }
            
        }
        Object StObject1 = getRequest().getParameter("start");
        if (StObject1 != null) {
            dateStart = Long.parseLong(StObject1.toString());
            SessionProvider.setSessionMapValue("DATEHOLIDAY", dateStart);
        }
        System.out.println("---------DATE TIME------" + dateStart);
        Object actionObjkect = getRequest().getParameter("action");
        if (actionObjkect != null) {
            if (actionObjkect.equals("addN500")) {
                Object objPn100 = getRequest().getParameter("PN100");
                if (objPn100 != null) {
                    PN100 = Util.parseInt(objPn100);
                }
                Object objPn000 = getRequest().getParameter("PN000");
                if (objPn000 != null) {
                    FN000 = Util.parseInt(objPn000);
                }
                Object objNv051 = getRequest().getParameter("NV051");
                if (objNv051 != null) {
                    nv502 = objNv051.toString();
                }
                
                 Object objh1 = getRequest().getParameter("h1");
                if (objh1 != null) {
                    h1 = Util.parseInt(objh1);
                }
                
                 Object objh2 = getRequest().getParameter("h2");
                if (objh2 != null) {
                    h2 = Util.parseInt(objh2);
                }
                
                 Object objh3 = getRequest().getParameter("h3");
                if (objh3 != null) {
                    h3 = Util.parseInt(objh3);
                }
                
                 Object objh4 = getRequest().getParameter("h4");
                if (objh4 != null) {
                    h4 = Util.parseInt(objh4);
                }
                Object objDateS = getRequest().getParameter("DATES");
                if (objDateS != null) {
                    SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
                    try {
                        ndn501 = format.parse(objDateS.toString());
                    } catch (ParseException ex) {
                        Logger.getLogger(N500Controller.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }
                Object objDateT = getRequest().getParameter("DATET");
                if (objDateT != null) {
                    SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
                    try {
                        ndn505 = format.parse(objDateT.toString());
                    } catch (ParseException ex) {
                        Logger.getLogger(N500Controller.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }

                Object nameMail = getRequest().getParameter("nameMail");
                if (nameMail != null) {
                    //SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy")               
                    nameMailTo = nameMail.toString();
                }

                Object nameMail1 = getRequest().getParameter("hoten");
                if (nameMail1 != null) {
                    //SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy")               
                    hotennghi = nameMail1.toString();
                }

                updateN500J();
            } else if (actionObjkect.equals("confirm")) {
                Object objDateT = getRequest().getParameter("PN500");
                if (objDateT != null) {
                    PN500 = Util.parseInt(objDateT);
                }

                //  updateStatus();
            }else if (actionObjkect.equals("datetoday")) {
                Object objDateT = getRequest().getParameter("pageString");
                if (objDateT != null) {
                    pageString = objDateT.toString();
                }

                //  updateStatus();
            }
        }

        Object id = getRequest().getParameter("id");
        Object date = getRequest().getParameter("date");
        Object adddate = getRequest().getParameter("adddate");

        if (adddate != null) {
            adddate1 = Integer.parseInt(adddate.toString());
        }
        if (id != null && date != null) {
            try {
                this.ndn501 = Util.parseDate(date.toString(), "dd/MM/yyyy");

            } catch (Exception e) {
                System.out.println(e.getMessage());
            }

            this.PN100 = Util.parseInt(id);
            System.out.println("PNNNNNNNNNNNNNNNNNNNNNNNNNNNN" + PN100);
            getDetailEditN500(PN100);
        }
        try {
            Object idpage = getRequest().getParameter("type");
            if (idpage != null) {
                if (idpage.equals("1")) {
                    SessionProvider.removeSessionMapValue("flag");
                    this.flagcalender = 1;
                    SessionProvider.setSessionMapValue("flag1", flagcalender);
                } else {
                    SessionProvider.removeSessionMapValue("flag1");
                    System.out.println("aaaaaaaaaaaaaaaaaaa" + flagcalender);
                    this.flagcalender = 0;
                    SessionProvider.setSessionMapValue("flag", flagcalender);
                }

            }
        } catch (Exception e) {
        }

        try {
            this.bophan = Integer.parseInt(SessionProvider.getSessionMapValue("FN450i").toString());
            this.phongban = Integer.parseInt(SessionProvider.getSessionMapValue("FN850i").toString());
        } catch (Exception e) {
        }

    }

    public void updateStatus() {
        try {

            DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
            //get current date time with Date()
            Date date = new Date();
            String date1 = dateFormat.format(date);


            CustomerStore store = new CustomerStore();
            int count = store.updateColumnN100("", "N500", "NV503", "B", "PN500", PN500, getLogin().getUserName());
            int count1 = store.updateColumnN100("", "N500", "NV506", note, "PN500", PN500, getLogin().getUserName());
            int count2 = store.updateColumnN100("", "N500", "NV507", getLogin().getHoten(), "PN500", PN500, getLogin().getUserName());
            int count3 = store.updateColumnN100("", "N500", "ND508", date1, "PN500", PN500, getLogin().getUserName());
            System.out.println("-------OUT !!!!------" + count);
            if (count > 0 || count1 > 0 || count2 > 0 || count3 > 0) {
                // setBeginContructor(1);
                showGlobalReport(true, getResourceString("datasavesuccessful"));
                sendRedirectUrlTab("detailCalender.jsp");
            } else {
                //  setBeginContructor(1);
                showGlobalReport(true, getResourceString("datasuccessfail"));
                sendRedirectUrlTab("detailCalender.jsp");
            }
        } catch (Exception e) {
        }
    }
    // CHange Q000

    public void changeCombQ000(ValueChangeEvent event) {
        try {
            int q000 = Util.parseInt(event.getNewValue().toString());
//        if(q000 >= 0){
//            SessionProvider.setSessionMapValue("Q000CALENDAR", q000);
//        }
            System.out.println("TUNGNS:--------WHEN CHANGE Q000------" + q000);
            if (q000 != 0) {
                getQ000SendById(q000);
            }

        } catch (Exception e) {
        }
    }

    public void updateN500J() {
        try {
            int timeCa = 0;
            String contentMail = "Tôi tên : " + hotennghi + " Ngày nghỉ :" + Util.toSQLDate(this.ndn501) + "đến ngày :" + Util.toSQLDate(this.ndn505) + "</br>"
                    + "Lý do nghỉ :" + nv502;
            if(h1!=0 || h3 !=0){
                timeCa = 1;
            }
            int row = n500Store.updateN500(getLogin().getModule(), getLogin().getCompanyNo(), this.PN100, 0, this.FN000, Util.toSQLDate(this.ndn501), this.nv502, "A", getLogin().getHoten(), Util.toSQLDate(this.ndn505),timeCa,h1,h2,h3,h4, getLogin().getUserName());
            if (row > 0) {
                setMassage("Đang cập nhật...");
                String nameM = null;
                String passM = null;
                if (SessionProvider.getSessionMapValue("NAMEEMAILSEND") != null) {
                    nameM = SessionProvider.getSessionMapValue("NAMEEMAILSEND").toString();
                }
                if (SessionProvider.getSessionMapValue("PASSEMAILSEND") != null) {
                    passM = SessionProvider.getSessionMapValue("PASSEMAILSEND").toString();
                }
                System.out.println("---------- THAM SO MAIL-------" + nameM + passM + nameMailTo + contentMail);
                sendMail(nameM, passM, nameMailTo, "ĐƠN XIN NGHỈ PHÉP", contentMail);
                showGlobalReport(true, getResourceString("datasavesuccessful"));
                setBeginContructor(1);
                sendRedirectUrlTab("detailCalender.jsp?action=datetoday&pageString=datetoday2&type=1");
            } else {
                setMassage("Cập nhật không thành công!");
                showGlobalReport(true, getResourceString("datasuccessfail"));
                setBeginContructor(0);
                sendRedirectUrlTab("detailCalender.jsp?action=datetoday&pageString=datetoday2&type=1");
            }
        } catch (Exception e) {
        }

    }
// get Password mail 

    public void getQ000SendById(int pq000) {
        Q000Store q000Store = new Q000Store();
        List<Q000> lst = q000Store.getListQ000(getLogin().getModule(), getLogin().getCompanyNo(), getLogin().getId(), getLogin().getUserName());
        if (lst != null) {
            System.out.println("D:- list getListAllQ000ByIDofMyprofile: " + lst.size());
        } else {
            System.out.println("D:- list getListAllQ000ByIDofMyprofile: null");
        }

        for (Q000 q000 : lst) {
            if (q000.getPQ000() == pq000) {
                this.nameMail = q000.getQV001();
                if (nameMail != null) {
                    SessionProvider.setSessionMapValue("NAMEEMAILSEND", nameMail);
                }
                this.passMail = q000.getQV002();
                if (passMail != null) {
                    SessionProvider.setSessionMapValue("PASSEMAILSEND", passMail);
                }
                System.out.println("------------EMAILLLLLLLLLLLLLLL--------" + nameMail + passMail);

            }
        }
    }

    public void reloadlist(ActionEvent ac) {
        try {

            if (FN850 >= 0) {
                SessionProvider.setSessionMapValue("FN850CALENDAR", FN850);
            }
            System.out.println("TUNGNS:--------WHEN SEARCH FOR N850------" + SessionProvider.getSessionMapValue("FN850CALENDAR"));
            sendRedirectUrlTab("employeeCalender.jsp");
        } catch (Exception e) {
        }



    }

    public void updateN500() {
        try {
            String dateStart1 = ContextUtil.getRequestParameter("dateStart");

            if (!dateStart1.equals("")) {
                ndn501 = Util.parseDate(dateStart1, "dd/MM/yyyy");

            } else {
                ndn501 = null;
            }
            String dateEnd1 = ContextUtil.getRequestParameter("dateEnd");
            if (!dateEnd1.equals("")) {
                ndn505 = Util.parseDate(dateEnd1, "dd/MM/yyyy");

            } else {
                ndn505 = null;
            }
            int row = n500Store.updateN500(getLogin().getModule(), getLogin().getCompanyNo(), this.PN100, 0, this.FN000, Util.toSQLDate(this.ndn501), this.nv502, null, null, Util.toSQLDate(this.ndn505),1,h1,h2,h3,h4, getLogin().getUserName());
            if (row > 0) {
                showGlobalReport(true, getResourceString("datasavesuccessful"));
            } else {
                showGlobalReport(true, getResourceString("datasuccessfail"));
            }
            try {

                int id = Integer.parseInt(SessionProvider.getSessionMapValue("flag1").toString());
                if (id == 1) {
                    sendRedirect("detailCalender.jsp?action=datetoday&pageString=datetoday2&type=1");
                }

            } catch (Exception e) {
            }
            try {
                int id1 = Integer.parseInt(SessionProvider.getSessionMapValue("flag").toString());
                if (id1 == 0) {
                    sendRedirect("employeeCalender.jsp");
                }
                //   sendRedirect("employeeCalender.jsp");
            } catch (Exception e) {
            }
        } catch (Exception e) {

            System.out.println(e.getMessage());
        }
    }
// danh sach nhan vien nghi phep trong thang

    public List<N500> getNCURPKS_LISTOFTABN500HOLI() {
        try {

            List<N500> listN500 = getN500Store().getNCURPKS_LISTOFTABN500HOLI(getLogin().getModule(), getLogin().getCompanyNo(), getLogin().getUserName());
            //  System.out.println("============FLIST N500==================" + listN500.size()+"====" +Util.toSQLDate(date));
            if(listN500.size() > 0 ){
                SessionProvider.setSessionMapValue("listN500", listN500);
            }
            return listN500;
        } catch (Exception e) {
            System.out.println("TUNGNS:-------ERROR1---LISTN500---" + e.getMessage());
            return null;
        }
    }
    // serch

    public void reload() {
        try {
            String date = ContextUtil.getRequestParameter("leavedate1");
            if (date.equals("") || date != null) {
                SessionProvider.setSessionMapValue("SEARCHDATECALENDER", date);
            }
            String date1 = ContextUtil.getRequestParameter("leavedate2");
            if (date1.equals("") || date1 != null) {
                SessionProvider.setSessionMapValue("SEARCHDATECALENDER1", date1);
            }
            sendRedirectUrlTab("detailCalender.jsp?type=1");
        } catch (Exception e) {
        }
    }

    public List<N500> getListAllN500() {
        try {
          
            if (SessionProvider.getSessionMapValue("SEARCHDATECALENDER") != null && SessionProvider.getSessionMapValue("SEARCHDATECALENDER1") != null) {
                String from = SessionProvider.getSessionMapValue("SEARCHDATECALENDER").toString();
                if (!from.equals("")) {
                    setDateF(Util.parseDate(from, "dd/MM/yyyy"));
                } else {
                    setDateF(null);
                }
                String to = SessionProvider.getSessionMapValue("SEARCHDATECALENDER1").toString();
                if (!to.equals("")) {
                    setDateT(Util.parseDate(to, "dd/MM/yyyy"));
                } else {
                    setDateT(null);
                }
                 List<N500> listN500 = new ArrayList<N500>();
                if(getPageString().equals("datetoday")){
                     listN500 = getN500Store().LISTOFTABN500M(getLogin().getModule(), getLogin().getCompanyNo(), FN850, 0, 0, Util.toSQLDate(dateF), Util.toSQLDate(dateT),1, getLogin().getUserName());
                }else if(getPageString().equals("datetoday1")){
                     listN500 = getN500Store().LISTOFTABN500M(getLogin().getModule(), getLogin().getCompanyNo(), FN850, 0, 0, Util.toSQLDate(dateF), Util.toSQLDate(dateT),0, getLogin().getUserName());
                }else{
                    listN500 = getN500Store().LISTOFTABN500M(getLogin().getModule(), getLogin().getCompanyNo(), FN850, 0, 0, Util.toSQLDate(dateF), Util.toSQLDate(dateT),0, getLogin().getUserName());
                }
                
               
                  System.out.println(pageString+"==========TIM KIEMMMMMMMMMMMMM==" + Util.toSQLDate(dateF) + Util.toSQLDate(dateT));
                return listN500;
            } else {
                if (dateStart == 0) {
                    if (SessionProvider.getSessionMapValue("DATEHOLIDAY") != null) {
                        dateStart = Long.valueOf(SessionProvider.getSessionMapValue("DATEHOLIDAY").toString());
                    }

                }
                if (dateEnd == 0) {
                    if (SessionProvider.getSessionMapValue("DATEHOLIDAYEND") != null) {
                        dateEnd = Long.valueOf(SessionProvider.getSessionMapValue("DATEHOLIDAYEND").toString());
                    }

                }
                Date date = new Date(dateStart);
                Date date1 = new Date(dateEnd);
                
                if (SessionProvider.getSessionMapValue("FN850CALENDAR") != null) {
                    FN850 = Util.parseInt(SessionProvider.getSessionMapValue("FN850CALENDAR"));
                } else {
                    FN850 = getLogin().getFn850();
                }
                System.out.println(pageString+"====SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS==" + getLogin().getModule()+","+ getLogin().getCompanyNo()+","+ FN850+","+ 0+","+ 0+","+ Util.toSQLDate(date)+","+ Util.toSQLDate(date1)+","+ getLogin().getUserName());
                System.out.println("-------------------------------AAAAAAAAAAAA----------"+getPageString().toString());
                List<N500> listN500 = new ArrayList<N500>();
                if(getPageString().equals("datetoday")){
                     listN500  = getN500Store().LISTOFTABN500M(getLogin().getModule(), getLogin().getCompanyNo(), FN850, 0, 0, Util.toSQLDate(date), Util.toSQLDate(date1),1, getLogin().getUserName());
                }else if(getPageString().equals("datetoday1")){
                    listN500  = getN500Store().LISTOFTABN500M(getLogin().getModule(), getLogin().getCompanyNo(), FN850, 0, 0, Util.toSQLDate(date), Util.toSQLDate(date1),0, getLogin().getUserName());
                }else{
                     listN500  = getN500Store().LISTOFTABN500M(getLogin().getModule(), getLogin().getCompanyNo(), FN850, 0, 0, Util.toSQLDate(date), Util.toSQLDate(date1),0, getLogin().getUserName());
                }
              
                System.out.println("============FLIST N500==================" + listN500.size() + "====" + Util.toSQLDate(date));
                return listN500;
            }

        } catch (Exception e) {
            System.out.println("TUNGNS:-------ERROR2---LISTN500---" + e.getMessage());
            return null;
        }
    }

    public void getDetailEditN500(int id) {
        try {
            List<N500> listN500Edit = getListAllN500();
            if (listN500Edit.size() > 0) {
                for (int i = 0; i < listN500Edit.size(); i++) {
                    if (listN500Edit.get(i).getFn100() == id) {


                        this.FN450 = listN500Edit.get(i).getFn450();

                        this.FN000 = listN500Edit.get(i).getFn000();
                        this.FN850 = listN500Edit.get(i).getFn850();
                        if (FN850 != 0) {
                            combN100 = comboboxUtil.getSelectedN900CombN500(FN850);
                        }
                        this.PN100 = listN500Edit.get(i).getFn100();
                        this.nv502 = listN500Edit.get(i).getNv502();
                        this.ndn501 = listN500Edit.get(i).getNd501();
                        this.ndn505 = listN500Edit.get(i).getNd505();
                        Calendar c = Calendar.getInstance();
                        try {

                            c.setTime(ndn505);
                            c.add(Calendar.DATE, adddate1);
                            ndn505 = Util.toSQLDate(c.getTime());

                        } catch (Exception e) {
                            System.out.println("=====" + e.getMessage());
                        }

                        System.out.println("TUNGNS:--------PARAM WHEN EDIT N500------" + FN850 + PN100);
                        break;
                    }
                }
            }
        } catch (Exception ex) {
            System.out.println("Error when getDetailEditN850. ERROR CODE: " + ex.getMessage());
        }
    }

    /**
     * @return the combN000
     */
    public List<SelectItem> getCombN000() {
        combN000 = getComboboxUtil().getListCombN000();
        return combN000;
    }

    /**
     * @param combN000 the combN000 to set
     */
    public void setCombN000(List<SelectItem> combN000) {
        this.combN000 = combN000;
    }

    /**
     * @return the FN000
     */
    public int getFN000() {
        return FN000;
    }

    /**
     * @param FN000 the FN000 to set
     */
    public void setFN000(int FN000) {
        this.FN000 = FN000;
    }

    /**
     * @return the FN850
     */
    public int getFN850() {

        if (SessionProvider.getSessionMapValue("FN850CALENDAR") != null) {
            FN850 = Util.parseInt(SessionProvider.getSessionMapValue("FN850CALENDAR"));
        } else {
            FN850 = getLogin().getFn850();
        }
        return FN850;
    }

    /**
     * @param FN850 the FN850 to set
     */
    public void setFN850(int FN850) {
        this.FN850 = FN850;
    }

    /**
     * @return the FN450
     */
    public int getFN450() {
        return FN450;
    }

    /**on
     * @param FN450 the FN450 to set
     */
    public void setFN450(int FN450) {
        this.FN450 = FN450;
    }

    /**
     * @return the PN100
     */
    public int getPN100() {
        return PN100;
    }

    /**
     * @param PN100 the PN100 to set
     */
    public void setPN100(int PN100) {
        this.PN100 = PN100;
    }

    /**
     * @return the ndn501
     */
    public Date getNdn501() {
        return ndn501;
    }

    /**
     * @param ndn501 the ndn501 to set
     */
    public void setNdn501(Date ndn501) {
        this.ndn501 = ndn501;
    }

    /**
     * @return the ndn505
     */
    public Date getNdn505() {
        return ndn505;
    }

    /**
     * @param ndn505 the ndn505 to set
     */
    public void setNdn505(Date ndn505) {
        this.ndn505 = ndn505;
    }

    /**
     * @return the nv502
     */
    public String getNv502() {
        return nv502;
    }

    /**
     * @param nv502 the nv502 to set
     */
    public void setNv502(String nv502) {
        this.nv502 = nv502;
    }

    /**
     * @return the comboboxUtil
     */
    public ComboboxUtil getComboboxUtil() {
        return comboboxUtil;
    }

    /**
     * @param comboboxUtil the comboboxUtil to set
     */
    public void setComboboxUtil(ComboboxUtil comboboxUtil) {
        this.comboboxUtil = comboboxUtil;
    }

    /**
     * @return the n500Store
     */
    public N500Store getN500Store() {
        return n500Store;
    }

    /**
     * @param n500Store the n500Store to set
     */
    public void setN500Store(N500Store n500Store) {
        this.n500Store = n500Store;
    }

    /**
     * @return the combN850
     */
    public List<SelectItem> getCombN850() {
        try {
            combN850 = comboboxUtil.getSelectedN850Comb();
            if (combN850 != null) {
                if (SessionProvider.getSessionMapValue("FN850CALENDAR") != null) {
                    FN850 = Util.parseInt(SessionProvider.getSessionMapValue("FN850CALENDAR"));
                } else {
                    try {
                        FN850 = getLogin().getFn850();
                    } catch (Exception e) {
                    }

                }
            }
            return combN850;
        } catch (Exception e) {
            return null;
        }

    }

    /**
     * @param combN850 the combN850 to set
     */
    public void setCombN850(List<SelectItem> combN850) {
        this.combN850 = combN850;
    }

    /**
     * @return the combN450
     */
    public List<SelectItem> getCombN450() {
        combN450 = comboboxUtil.getListComBN450();
        return combN450;
    }

    public void changeCombN450forN850(ValueChangeEvent event) {
        this.FN450 = Integer.parseInt(event.getNewValue().toString());
        SessionProvider.setSessionMapValue("FN450i", FN450);
        System.out.println("-----------action change com ------" + this.FN450);
        combN850 = comboboxUtil.getlistCombN850FindId(Integer.parseInt(event.getNewValue().toString()));
    }

    public void changeCombN850forN100(ValueChangeEvent event) {
        this.FN850 = Integer.parseInt(event.getNewValue().toString());

        System.out.println("TNS:-----------ID FOR FN850 ------" + event.getNewValue().toString());
        combN100 = comboboxUtil.getSelectedN900CombN500(Integer.parseInt(event.getNewValue().toString()));
    }

    public void changeCombN850forN100ofCalendar(ValueChangeEvent event) {



        int fn850Id = Util.parseInt(event.getNewValue().toString());
        if (fn850Id >= 0) {
            SessionProvider.setSessionMapValue("FN850CALENDAR", fn850Id);
        }
        System.out.println("TUNGNS:--------WHEN SEARCH FOR N850------" + SessionProvider.getSessionMapValue("FN850CALENDAR"));
        sendRedirectUrlTab("employeeCalender.jsp");
    }

    // GUi mail cho nguoi quan lý 
    public void sendMail(String username, String pass, String email, String subject, String content) {
        String SMTP_AUTH_USER = "";
        String SMTP_AUTH_PWD = "";
        String SMTP_HOST_NAME = "smtp.gmail.com";
        int SMTP_HOST_PORT = 465;
        try {
            SMTP_AUTH_USER = username;//your email address
            SMTP_AUTH_PWD = pass;//your password
            Properties props = new Properties();

            props.put("mail.transport.protocol", "smtps");
            props.put("mail.smtp.host", SMTP_HOST_NAME);
            props.put("mail.smtps.auth", "true");
            props.put("mail.smtp.starttls.enable", "true");
            props.put("mail.smtps.from", "kakaka@machine");

            Session mailSession = Session.getInstance(props);
            mailSession.setDebug(true);
            Transport transport = mailSession.getTransport();
            System.out.append("---------------1\n");

            MimeMessage message = new MimeMessage(mailSession);
            message.setSubject(subject, "utf-8");

            MimeMultipart multipart = new MimeMultipart("mixed");
            message.setContent(multipart);

            message.addRecipient(Message.RecipientType.BCC, new InternetAddress(email));

            transport.connect(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);
            System.out.append("---------------2\n");

            MimeBodyPart textMBCC = new MimeBodyPart();
            textMBCC.setContent(content, "text/html; charset=utf-8");
            multipart.addBodyPart(textMBCC);
            Address[] st = new Address[1];
            st[0] = new InternetAddress(email);
            transport.sendMessage(message, st);

            transport.close();

        } catch (Exception e) {
            System.out.println("--D: Error from sendmail: " + e.getMessage());
            //   chkMess = true;
        }
    }

    public void changeComN850List(ValueChangeEvent event) {
        try {
            int fn850Id = Util.parseInt(event.getNewValue().toString());
            if (fn850Id >= 0) {
                SessionProvider.setSessionMapValue("FN850CALENDAR", fn850Id);
            }
            System.out.println("TUNGNS:--------WHEN SEARCH FOR N850------" + SessionProvider.getSessionMapValue("FN850CALENDAR"));
            sendRedirectUrlTab("detailCalender.jsp");
        } catch (Exception e) {
        }
    }

    public void changeCombN450forN850ofCalender(ValueChangeEvent event) {
        this.bophan = Integer.parseInt(event.getNewValue().toString());
        SessionProvider.setSessionMapValue("FN450i", bophan);
        // System.out.println("-----------action change com ------" + this.FN450);
        combN850 = comboboxUtil.getlistCombN850FindId(Integer.parseInt(event.getNewValue().toString()));
    }

    /**
     * @param combN450 the combN450 to set
     */
    public void setCombN450(List<SelectItem> combN450) {
        this.combN450 = combN450;
    }

    /**
     * @return the combN100
     */
    public List<SelectItem> getCombN100() {


//        try {
//            combN100 = comboboxUtil.getlistCombN100FindId(FN850);
//        } catch (Exception e) {
//            System.out.println(e.getMessage());
//        }

        return combN100;
    }

    /**
     * @param combN100 the combN100 to set
     */
    public void setCombN100(List<SelectItem> combN100) {
        this.combN100 = combN100;
    }

    /**
     * @return the adddate1
     */
    public int getAdddate1() {
        return adddate1;
    }

    /**
     * @param adddate1 the adddate1 to set
     */
    public void setAdddate1(int adddate1) {
        this.adddate1 = adddate1;
    }

    /**
     * @return the phongban
     */
    public int getPhongban() {
        return phongban;
    }

    /**
     * @param phongban the phongban to set
     */
    public void setPhongban(int phongban) {
        this.phongban = phongban;
    }

    /**
     * @return the bophan
     */
    public int getBophan() {
        return bophan;
    }

    /**
     * @param bophan the bophan to set
     */
    public void setBophan(int bophan) {
        this.bophan = bophan;
    }

    /**
     * @return the flagcalender
     */
    public int isFlagcalender() {
        return flagcalender;
    }

    /**
     * @param flagcalender the flagcalender to set
     */
    public void setFlagcalender(int flagcalender) {
        this.flagcalender = flagcalender;
    }

    /**
     * @return the beginContructor
     */
    public int getBeginContructor() {
        return beginContructor;
    }

    /**
     * @param beginContructor the beginContructor to set
     */
    public void setBeginContructor(int beginContructor) {
        this.beginContructor = beginContructor;
    }

    /**
     * @return the comN900
     */
    public List<SelectItem> getComN900() {

        return comboboxUtil.getSelectedN900Calendar(0);
    }

    /**
     * @param comN900 the comN900 to set
     */
    public void setComN900(List<SelectItem> comN900) {
        this.comN900 = comN900;
    }

    /**
     * @return the status
     */
    public String getStatus() {
        return status;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(String status) {
        this.status = status;
    }

    /**
     * @return the PN500
     */
    public int getPN500() {
        return PN500;
    }

    /**
     * @param PN500 the PN500 to set
     */
    public void setPN500(int PN500) {
        this.PN500 = PN500;
    }

    /**
     * @return the nameMail
     */
    public String getNameMail() {
        return nameMail;
    }

    /**
     * @param nameMail the nameMail to set
     */
    public void setNameMail(String nameMail) {
        this.nameMail = nameMail;
    }

    /**
     * @return the passMail
     */
    public String getPassMail() {
        return passMail;
    }

    /**
     * @param passMail the passMail to set
     */
    public void setPassMail(String passMail) {
        this.passMail = passMail;
    }

    /**
     * @return the nameMailTo
     */
    public String getNameMailTo() {
        return nameMailTo;
    }

    /**
     * @param nameMailTo the nameMailTo to set
     */
    public void setNameMailTo(String nameMailTo) {
        this.nameMailTo = nameMailTo;
    }

    /**
     * @return the hotennghi
     */
    public String getHotennghi() {
        return hotennghi;
    }

    /**
     * @param hotennghi the hotennghi to set
     */
    public void setHotennghi(String hotennghi) {
        this.hotennghi = hotennghi;
    }

    /**
     * @return the massage
     */
    public String getMassage() {
        return massage;
    }

    /**
     * @param massage the massage to set
     */
    public void setMassage(String massage) {
        this.massage = massage;
    }

    /**
     * @return the note
     */
    public String getNote() {
        return note;
    }

    /**
     * @param note the note to set
     */
    public void setNote(String note) {
        this.note = note;
    }

    /**
     * @return the dateEnd
     */
    public long getDateEnd() {
        return dateEnd;
    }

    /**
     * @param dateEnd the dateEnd to set
     */
    public void setDateEnd(long dateEnd) {
        this.dateEnd = dateEnd;
    }

    /**
     * @return the dateF
     */
    public Date getDateF() {
        return dateF;
    }

    /**
     * @param dateF the dateF to set
     */
    public void setDateF(Date dateF) {
        this.dateF = dateF;
    }

    /**
     * @return the dateT
     */
    public Date getDateT() {
        return dateT;
    }

    /**
     * @param dateT the dateT to set
     */
    public void setDateT(Date dateT) {
        this.dateT = dateT;
    }

    /**
     * @return the h1
     */
    public int getH1() {
        return h1;
    }

    /**
     * @param h1 the h1 to set
     */
    public void setH1(int h1) {
        this.h1 = h1;
    }

    /**
     * @return the h2
     */
    public int getH2() {
        return h2;
    }

    /**
     * @param h2 the h2 to set
     */
    public void setH2(int h2) {
        this.h2 = h2;
    }

    /**
     * @return the h3
     */
    public int getH3() {
        return h3;
    }

    /**
     * @param h3 the h3 to set
     */
    public void setH3(int h3) {
        this.h3 = h3;
    }

    /**
     * @return the h4
     */
    public int getH4() {
        return h4;
    }

    /**
     * @param h4 the h4 to set
     */
    public void setH4(int h4) {
        this.h4 = h4;
    }

    /**
     * @return the pageString
     */
    public String getPageString() {
        return pageString;
    }

    /**
     * @param pageString the pageString to set
     */
    public void setPageString(String pageString) {
        this.pageString = pageString;
    }

    /**
     * @return the pn500
     */
    public int getPn500() {
        return pn500;
    }

    /**
     * @param pn500 the pn500 to set
     */
    public void setPn500(int pn500) {
        this.pn500 = pn500;
    }
    
}
